﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.ComponentModel;
using System.Diagnostics;
using System.Data.SqlClient;
using System.IO;
//using MyWeb.DataAccessHelper;
//namespace MyWeb.DataAccessLayer
//{
public class Datacon
{
    
    dbname dbname = new dbname();
    public SqlConnection getcon()
    {
        //请修改此处的连接代码
        string strCon = ConfigurationManager.ConnectionStrings["wx_zilaishui_yanshiConnectionString"].ConnectionString;
        //string strCon = "Data Source=.;Initial Catalog="+   dbname.getdbname()+";Persist Security Info=True;User ID=sa;password=qwertyui123";
                        //Data Source=.;Initial Catalog=wx_zilaishui_yanshi;Persist Security Info=True;User ID=sa;Password=qwertyui123                
        //Data Source=.;Initial Catalog=wx_zilaishui_yanshi;Persist Security Info=True;User ID=sa;Password=qwertyui123"
   
        
        SqlConnection sqlCon = new SqlConnection(strCon);
        //WriteLogclass(strCon);
        return sqlCon;
    }

    public void WriteLogclass(string strMemo)
    {

        string filename = System.Web.HttpContext.Current.Server.MapPath("~/") + "logs\\log.txt";

        if (!Directory.Exists(System.Web.HttpContext.Current.Server.MapPath("~/") + ("logs\\")))

            Directory.CreateDirectory("\\logs\\");

        StreamWriter sr = null;

        try
        {

            if (!File.Exists(filename))
            {

                sr = File.CreateText(filename);

            }

            else
            {

                sr = File.AppendText(filename);

            }

            sr.WriteLine(strMemo);

        }

        catch
        {

        }

        finally
        {

            if (sr != null)

                sr.Close();

        }

    }


    private string dushujukuming()
    {

        string strLine;
        try
        {
            string filename = System.Web.HttpContext.Current.Server.MapPath("~/") + "databasename.txt";
           
            FileStream aFile = new FileStream(filename, FileMode.Open);
            StreamReader sr = new StreamReader(aFile);
            strLine = sr.ReadLine();
            sr.Close();
            return strLine;
        }
        catch (IOException ex)
        {
            Console.WriteLine("An IOException has been thrown!");
            Console.WriteLine(ex.ToString());
            Console.ReadLine();
            return "";
        }

    }

}

